# Contributor: Christine Dodrill <me@christine.website>
# Maintainer: omni <omni+alpine@hack.org>
pkgname=tor
pkgver=0.4.8.10
pkgrel=0
pkgdesc="Anonymous network connectivity"
url="https://www.torproject.org/"
arch="all !s390x" # The extended_fmt test fail, try again next bump/upgrade
license="BSD-3-Clause AND GPL-3.0-only"
pkgusers="tor"
makedepends="ca-certificates
	libcap-dev
	libevent-dev
	libseccomp-dev
	openssl-dev>3
	xz-dev
	zlib-dev
	zstd-dev"
install="$pkgname.pre-install"
subpackages="$pkgname-doc $pkgname-openrc"
source="https://www.torproject.org/dist/tor-$pkgver.tar.gz
	0002-disable-wildcard-escaping-test.patch
	0003-disable-sandbox_chown_filename-test_patch
	0004-disable-more-sandbox-tests_patch
	tor.initd
	tor.confd
	torrc.sample.patch
	"

# secfixes:
#   0.4.7.8-r0:
#     - CVE-2022-33903
#   0.4.6.7-r0:
#     - CVE-2021-38385
#   0.4.6.5-r0:
#     - CVE-2021-28548
#     - CVE-2021-28549
#     - CVE-2021-28550
#   0.4.5.7-r0:
#     - CVE-2021-28089
#     - CVE-2021-28090
#   0.4.2.7-r0:
#     - CVE-2020-10592
#     - CVE-2020-10593
#   0.3.5.8-r0:
#     - CVE-2019-8955
#   0.3.0.8-r0:
#     - CVE-2017-0376
#   0.3.2.10-r0:
#     - CVE-2018-0490
#     - CVE-2018-0491

build() {
	./configure \
		--build="$CBUILD" \
		--host="$CHOST" \
		--prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--mandir=/usr/share/man \
		--enable-gpl \
		--disable-html-manual
	make
}

check() {
	# FIXME: find out why these specific tests only fail on these archs
	case "$CARCH" in
	aarch64)
		patch src/test/test_sandbox.c \
		"$srcdir"/0003-disable-sandbox_chown_filename-test_patch
		patch src/test/test_sandbox.c \
		"$srcdir"/0004-disable-more-sandbox-tests_patch
		;;
	arm*) patch src/test/test_sandbox.c \
		"$srcdir"/0003-disable-sandbox_chown_filename-test_patch
		;;
	esac

	# TODO: use 'make check' instead, may need to update some skips !49207
	make test
}

package() {
	make DESTDIR="$pkgdir" install

	install -dm0755 -o "$pkgusers" \
		"$pkgdir"/var/lib/"$pkgname" \
		"$pkgdir"/var/log/"$pkgname"

	install -Dm0755 "$srcdir"/"$pkgname".initd \
		"$pkgdir"/etc/init.d/"$pkgname"
	install -Dm0644 "$srcdir"/"$pkgname".confd \
		"$pkgdir"/etc/conf.d/"$pkgname"
}

sha512sums="
3827902541a0289ed1bfcae9bb0ac8bf8dee7bedacbfdf9c703bb38c3c586d1cfe5eeb20a477664e10a2b81b90a7fd5d623e556f3ee32aad4f8a9f828bc4dd83  tor-0.4.8.10.tar.gz
c18e54a07de2baf50c3fbf0d100e964e0f39310f41df332507e737a1da3fa5d478445f679534d244f7d3978b341aa4723ca22830294ec409e6863476bd46356f  0002-disable-wildcard-escaping-test.patch
44a72a72a140c4fc7f3ce03b8a9a2b9244d6330ec5939778a2132470b8012676a5239fbb4b5a8b6dd80bf20f51e54d8e4a5b03384b0ec5a3aff22e22ee2970f5  0003-disable-sandbox_chown_filename-test_patch
2ea6ac4e02134903d85dc91ba90a20a94f95a0e950225c670b1364046277ba2fb4b6ab00d5d7d1b9dbfc072ee18c54603dd87ed8e4321362ca7102f8a965287d  0004-disable-more-sandbox-tests_patch
6de4ada16ba58264a247da70343eabd763e992d6b6683977fc1c67b7b4a9731748a7ec9751e869ad4b4ae9c72cf71b2e12dc289bb6e2aee499917f7663f4a735  tor.initd
2b0de119bfdf9eb57e13317b7392190b1b8272c8f96023c71d3fc29215d887e9a3d0ffcef37cdb50b18d34e4b2251f75a739e258e0bb72aabd3339418b22fd67  tor.confd
da386ff7e387312e647f04d360517a1f4cb1efbee36f4a3a6feb89a979bb12fa350fe6dfed49af0cb076ae30bb0c527b5d54127683eaa5aa45d6940dddd89dfb  torrc.sample.patch
"
